* Multiproduct Firms, Horizontal Mergers, and International Trade
* Jackie M.L. Chan, Michael Irlacher, and Michael Koch

* This do file computes statistics for all stylized facts in Appendix Table A.4.

postfile stats str32 varname str32 sample str32 statistic N mean sd using "D:\Data\Workdata\703989\FJSJ3989\CIK\replication_restat\output\table_A4.dta", replace

* Baseline definition: Horizontal within 4-digit industry
post stats ("Column 1") ("") ("") (.) (.) (.)

* From Do File #P5
use "D:\Data\Workdata\703989\FJSJ3989\CIK\replication_restat\data\temp_mergers_all_largestT_1865.dta", clear

do "D:\Data\Workdata\703989\FJSJ3989\CIK\replication_restat\dofiles\R3b.table_A4_1.do"

use "D:\Data\Workdata\703989\FJSJ3989\CIK\replication_restat\data\temp_mergers_all_largestT_1865.dta", clear

do "D:\Data\Workdata\703989\FJSJ3989\CIK\replication_restat\dofiles\R3c.table_A4_2.do"

* From Do File #P8b
use "D:\Data\Workdata\703989\FJSJ3989\CIK\replication_restat\data\temp_vars_com_product_cn8plus.dta", clear

do "D:\Data\Workdata\703989\FJSJ3989\CIK\replication_restat\dofiles\R3d.table_A4_3.do"

use "D:\Data\Workdata\703989\FJSJ3989\CIK\replication_restat\data\temp_vars_com_product_cn8plus.dta", clear

do "D:\Data\Workdata\703989\FJSJ3989\CIK\replication_restat\dofiles\R3e.table_A4_4.do"

********************************************************************************

* Non-horizontal outside 4-digit industry 
use "D:\Data\Workdata\703989\FJSJ3989\CIK\replication_restat\data\list_1992-2018_combined1865.dta", clear 
rename cvrnrA cvrnr
merge m:1 cvrnr aar using "D:\Data\Workdata\703989\FJSJ3989\CIK\replication_restat\data\cvrnr_industry_jc.dta", keep(match) nogen
rename cvrnr cvrnrA
rename CVR_BRANCHE_DB07 indA
rename cvrnrT cvrnr
merge 1:1 cvrnr aar using "D:\Data\Workdata\703989\FJSJ3989\CIK\replication_restat\data\cvrnr_industry_jc.dta", keep(match) nogen
rename CVR_BRANCHE_DB07 indT
rename cvrnr cvrnrT

gen d_si=0 
replace d_si=1 if indA==indT

gen indA2 = floor(indA/10000)
gen indA4 = floor(indA/100)
gen indT2 = floor(indT/10000)
gen indT4 = floor(indT/100)

gen d_si2 = (indA2==indT2)
gen d_si4 = (indA4==indT4)

keep if aar>=1996 & aar<=2015

egen maxd_si4 = max(d_si4), by(cvrnrA aar)
keep if maxd_si4==0
gsort cvrnrA aar -employee_cvrnrT cvrnrT
by cvrnrA aar: gen dup = _n
tempfile templargestT
save `templargestT.dta', replace

post stats ("Column 2") ("") ("") (.) (.) (.)

do "D:\Data\Workdata\703989\FJSJ3989\CIK\replication_restat\dofiles\R3b.table_A4_1.do"

use `templargestT.dta', clear

do "D:\Data\Workdata\703989\FJSJ3989\CIK\replication_restat\dofiles\R3c.table_A4_2.do"

* From Do File #P8d
use "D:\Data\Workdata\703989\FJSJ3989\CIK\replication_restat\data\temp_vars_com_product_cn8plus_nonhd4.dta", clear

do "D:\Data\Workdata\703989\FJSJ3989\CIK\replication_restat\dofiles\R3d.table_A4_3.do"

use "D:\Data\Workdata\703989\FJSJ3989\CIK\replication_restat\data\temp_vars_com_product_cn8plus_nonhd4.dta", clear

do "D:\Data\Workdata\703989\FJSJ3989\CIK\replication_restat\dofiles\R3e.table_A4_4.do"

********************************************************************************

* Non-horizontal outside 4-digit main product group
use "D:\Data\Workdata\703989\FJSJ3989\CIK\replication_restat\data\list_1992-2018_combined1865.dta", clear 
rename cvrnrA cvrnr
merge m:1 cvrnr aar using "D:\Data\Workdata\703989\FJSJ3989\CIK\replication_restat\data\cvrnr_industry_jc.dta", keep(match) nogen
rename cvrnr cvrnrA
rename CVR_BRANCHE_DB07 indA
rename cvrnrT cvrnr
merge 1:1 cvrnr aar using "D:\Data\Workdata\703989\FJSJ3989\CIK\replication_restat\data\cvrnr_industry_jc.dta", keep(match) nogen
rename CVR_BRANCHE_DB07 indT
rename cvrnr cvrnrT

gen d_si=0 
replace d_si=1 if indA==indT

gen indA2 = floor(indA/10000)
gen indA4 = floor(indA/100)
gen indT2 = floor(indT/10000)
gen indT4 = floor(indT/100)

gen d_si2 = (indA2==indT2)
gen d_si4 = (indA4==indT4)

keep if aar>=1996 & aar<=2015

egen maxd_si4 = max(d_si4), by(cvrnrA aar)

gsort cvrnrA aar -employee_cvrnrT cvrnrT
by cvrnrA aar: gen dup = _n
tempfile templargestT
save `templargestT.dta', replace

use "D:\Data\Workdata\703989\FJSJ3989\CIK\replication_restat\data\temp_vars_com_product_hs4_allmergers.dta", clear 
keep if samecore==0
rename cvrnrT cvrnrT_combined
merge 1:m cvrnrA aar using `templargestT.dta', keep(match) nogen
tempfile templargestT
save `templargestT.dta', replace

post stats ("Column 3") ("") ("") (.) (.) (.)

do "D:\Data\Workdata\703989\FJSJ3989\CIK\replication_restat\dofiles\R3b.table_A4_1.do"

use `templargestT.dta', clear

do "D:\Data\Workdata\703989\FJSJ3989\CIK\replication_restat\dofiles\R3c.table_A4_2.do"

* From Do File #P8e
use "D:\Data\Workdata\703989\FJSJ3989\CIK\replication_restat\data\temp_vars_com_hs4_differentcore_product_cn8plus.dta", clear

do "D:\Data\Workdata\703989\FJSJ3989\CIK\replication_restat\dofiles\R3d.table_A4_3.do"

use "D:\Data\Workdata\703989\FJSJ3989\CIK\replication_restat\data\temp_vars_com_hs4_differentcore_product_cn8plus.dta", clear

do "D:\Data\Workdata\703989\FJSJ3989\CIK\replication_restat\dofiles\R3e.table_A4_4.do"

********************************************************************************

* Non-horizontal outside 4-digit industry and 4-digit main product group
use "D:\Data\Workdata\703989\FJSJ3989\CIK\replication_restat\data\list_1992-2018_combined1865.dta", clear 
rename cvrnrA cvrnr
merge m:1 cvrnr aar using "D:\Data\Workdata\703989\FJSJ3989\CIK\replication_restat\data\cvrnr_industry_jc.dta", keep(match) nogen
rename cvrnr cvrnrA
rename CVR_BRANCHE_DB07 indA
rename cvrnrT cvrnr
merge 1:1 cvrnr aar using "D:\Data\Workdata\703989\FJSJ3989\CIK\replication_restat\data\cvrnr_industry_jc.dta", keep(match) nogen
rename CVR_BRANCHE_DB07 indT
rename cvrnr cvrnrT

gen d_si=0 
replace d_si=1 if indA==indT

gen indA2 = floor(indA/10000)
gen indA4 = floor(indA/100)
gen indT2 = floor(indT/10000)
gen indT4 = floor(indT/100)

gen d_si2 = (indA2==indT2)
gen d_si4 = (indA4==indT4)

keep if aar>=1996 & aar<=2015

egen maxd_si4 = max(d_si4), by(cvrnrA aar)
keep if maxd_si4==0
gsort cvrnrA aar -employee_cvrnrT cvrnrT
by cvrnrA aar: gen dup = _n
tempfile templargestT
save `templargestT.dta', replace

use "D:\Data\Workdata\703989\FJSJ3989\CIK\replication_restat\data\temp_vars_com_product_hs4_allmergers.dta", clear 
keep if samecore==0
rename cvrnrT cvrnrT_combined
merge 1:m cvrnrA aar using `templargestT.dta', keep(match) nogen
tempfile templargestT
save `templargestT.dta', replace

post stats ("Column 4") ("") ("") (.) (.) (.)

do "D:\Data\Workdata\703989\FJSJ3989\CIK\replication_restat\dofiles\R3b.table_A4_1.do"

use `templargestT.dta', clear

do "D:\Data\Workdata\703989\FJSJ3989\CIK\replication_restat\dofiles\R3c.table_A4_2.do"

* From Do File #P8f
use "D:\Data\Workdata\703989\FJSJ3989\CIK\replication_restat\data\temp_vars_com_hs4_differentcore_nonhd4_product_cn8plus.dta", clear

do "D:\Data\Workdata\703989\FJSJ3989\CIK\replication_restat\dofiles\R3d.table_A4_3.do"

use "D:\Data\Workdata\703989\FJSJ3989\CIK\replication_restat\data\temp_vars_com_hs4_differentcore_nonhd4_product_cn8plus.dta", clear

do "D:\Data\Workdata\703989\FJSJ3989\CIK\replication_restat\dofiles\R3e.table_A4_4.do"

postclose stats
